package com.liliya.servlet.ad;

import com.liliya.pojo.Ad;
import com.liliya.service.AdService;
import com.liliya.service.impl.AdServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description TODO
 * @Author hhy
 * @Date 2021/1/9 14:17
 */
@WebServlet(urlPatterns = "/ad/del")
public class AdDelServlet extends HttpServlet {
    private AdService adService = new AdServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        AdServiceImpl adService = new AdServiceImpl();
        String adnum = req.getParameter("adnum");
        if (adnum==null) resp.sendRedirect("manage.jsp"); //如果拿不到数据那就跳转回去
        Ad ad = adService.findAdByAdNum(Integer.parseInt(adnum));
        req.setAttribute("ad",ad);
        req.getRequestDispatcher("./addel.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String adnum = req.getParameter("adnum");
        adService.deleteAd(Integer.parseInt(adnum));
    }
}
